package com.qiangqiang.service;

import com.qiangqiang.aop.annotation.CheckHasDormitory;
import com.qiangqiang.dto.SanitationDTO;
import com.qiangqiang.repository.SanitationRepository;
import com.qiangqiang.util.KeyUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * Created by q on 2018/2/15.
 */
@Slf4j
@Service
public class SanitationService {

    @Autowired
    private SanitationRepository sanitationRepository;

    public List<SanitationDTO> findAllByDid(String dId){
        return sanitationRepository.queryAllByDId(dId).stream()
                .map(e->{
                    SanitationDTO sanitationDTO=new SanitationDTO();
                    BeanUtils.copyProperties(e,sanitationDTO);
                    return sanitationDTO;
                }).collect(Collectors.toList());
    }

    @CheckHasDormitory
    public void addSanitationRecord(String dId,Integer level){
        sanitationRepository.insertSanitation(KeyUtil.getUniqueKey(),dId,level);
    }

}
